#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<ll,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

int to[N],h[N],cnt,n,m,d[N];
ll dis[N];
bool vis[N];
struct edge{int v,w,nxt;}e[N<<1];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void dijk(int s){
	priority_queue<pii> q; memset(dis,0x3f,sizeof(dis)); dis[s] = 0; q.push(pii(-dis[s],s));
	while(q.size()){
		int x = q.top().se; q.pop(); if(vis[x]) continue; vis[x] = 1;
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] >= dis[x] + e[i].w){
				dis[y] = dis[x] + e[i].w;
				to[y] = i; q.push(pii(-dis[y],y));
			}
		}
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1,u,v,w;i <= m;i++){
		u = in,v = in;w = in,link(u,v,w);link(v,u,w);
	}
	dijk(in);
	for(int i = 1;i <= n;i++) d[i] = to[i] + 1 >> 1;
	ll ans = 0;
	for(int i = 1;i <= n;i++) ans += e[to[i]].w;
	sort(d+1,d+n+1);
	printf("%lld\n",ans);
	for(int i = 2;i <= n;i++) printf("%d ",d[i]);
	return 0;
}

